package com.ruoyi.wechat.service.impl;

import com.ruoyi.wechat.domain.CampFacility;
import com.ruoyi.wechat.domain.FacilityType;
import com.ruoyi.wechat.mapper.FacilityTypeMapper;
import com.ruoyi.wechat.service.ICampFacilityService;
import com.ruoyi.wechat.service.IWxFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WxFacilityServiceImpl implements IWxFacilityService {
    @Resource
    private FacilityTypeMapper facilityTypeMapper;
    @Override
    public List<FacilityType> getFacilityTypeAndFacility() {
        return facilityTypeMapper.getFacilityTypeAndFacility();
    }

    @Autowired
    private ICampFacilityService campFacilityService;

    /**
     * 营地设施记录表新增数据
     * @param campId
     * @param facilityIds
     * @return
     */
    @Override
    @Transactional
    public int add(String campId, String[] facilityIds) {
//根据营地id,删除所属设施id
        campFacilityService.deleteCampFacilityByCampId(campId);
        //循环新增营地id和设施id到记录表中
        for (int i = 0; i < facilityIds.length; i++) {
         CampFacility campFacility =new CampFacility();
         campFacility.setFacilityId(facilityIds[i]);
         campFacility.setCampId(campId);
         campFacilityService.insertCampFacility(campFacility);
        }
        return 1;
    }

    @Override
    public List<FacilityType> campFacilityListCampId(String campId) {
        return facilityTypeMapper.selectFacilityTypeAndFacilityByCampId(campId);
    }

    @Override
    public int deleteCampFacilityByCampId(String campId) {
        return campFacilityService.deleteCampFacilityByCampId(campId);
    }


}
